from flask import Blueprint, jsonify, request
from applications.ai.pack_ada_dt_class import train_and_predict_nanoenzyme_type
from applications.ai.pack_gbr_res import predict_advanced
from applications.ai.pack_gbr_res import find_similar_formula

bp = Blueprint('prediction', __name__, url_prefix='/prediction')


@bp.post('/base')
def base():
    req_json = request.get_json(force=True)

    # 初始化一个新的字典，用于存储处理后的数据
    processed_json = {}

    # 遍历 req_json 中的每个键值对
    for key, value in req_json.items():
        # 去除字符串两端的空白字符，并检查结果是否为空
        cleaned_value = value.strip()
        processed_json[key] = cleaned_value if cleaned_value != '' else None

    # processed_json 现在包含处理后的数据，其中空字符串和空格已替换为 None

    # input name
    nano_enzyme_formula = processed_json.get('nano_enzyme_formula')

    # pred
    predicted_type = train_and_predict_nanoenzyme_type(nano_enzyme_formula)

    res = {
        "data": {
            "Catalytic activity": predicted_type
        }
    }
    return jsonify(res)


@bp.post('/advanced')
def advanced():
    mapping = {
        "Chemical_formula": {
            "Pd/rGO": 0,
            "Cu/rGO": 1,
            "Cu-Pd/rGO": 2,
            "Cu-Pd/g-C3N4": 3,
            "Cu-Pd/g-C3N5": 4,
            "Cu-Pd/MoS2": 5,
            "Cu-Pd/MoS3": 6,
            "Pt NPs": 7,
            "Pd@Pt": 8,
            "Pd": 9,
            "Au0.75Pt0.25": 10,
            "Au0.5Pt0.5": 11,
            "Au0.25Pt0.75": 12,
            "Au0.15Pt0.85": 13,
            "Pt": 14,
            "Fe3C/N?C": 15,
            "Fe/NC": 16,
            "Mn3O4 NPs": 17,
            "CeO2": 18,
            "TiO2/C-QDs": 19,
            "MoO3-TPP ": 20,
            "MnO2": 21,
            "Co4S3/Co(OH)2 HNTs": 22,
            "Co-V MMOs": 23,
            "MNPG": 24,
            "Ir/NC": 25,
            "Ir/C": 26,
            "MnO2 + GA": 27,
            "汐-MnO2": 28,
            "汕-MnO2": 29,
            "污-MnO2": 30,
            "Mn3O4": 31,
            "K5PV2Mo10O40": 32,
            "Fe-N/C-CNTs": 33,
            "Ni-N/C-CNTs": 34,
            "Co-N/C-CNTs": 35,
            "AuNPs": 36,
            "AuPtNPs": 37,
            "MIP(AuPt)": 38,
            "cerium oxide nanoparticles": 39,
            "CeO2/rGO": 40,
            "LaMnO3+汛 nanofibers": 41,
            "V6O13每rGO": 42,
            "V6O13每rGO + F\u0002": 43,
            "CNF/MnCo2O4.5": 44,
            "V6O13 nanotextiles": 45,
            "VO2(A)": 46,
            "Ni(OH)2 NFs": 47,
            "NiO NFs": 48,
            "TiO2@CeOx": 49,
            "Sisal-like Co3O4": 50,
            "FeBi-NC SAzyme": 51,
            "FeN5 SACs-Heme": 52,
            "FeN4 SACs-Heme": 53,
            "A30AS1411-AuNF": 54,
            "Fe-Ac-NH2-UiO-66 NPs": 55,
            "Fe-HCl-NH2-UiO-66 NPs": 56,
            "FeBNC": 57,
            "FeNC": 58,
            "SO42? /CoFe2O4": 59,
            "Au NRs-Pd@HA": 60,
            "CoNCDs": 61,
            "Fe-MoOv": 62,
            "Au25": 63,
            "Au24Cu1": 64,
            "Au24Cd1": 65,
            "Au24Ag1": 66,
            "Ag3PO4 MCs ": 67,
            "Ag@Ag3PO4MCs": 68,
            "Ag3PO4": 69,
            "NiPd hNPs": 70,
            "MgFe2O4 MNPs": 71,
            "NiFe2O4 MNPs": 72,
            "3DRGO_Fe3O4-Pd": 73,
            "Pd-Ir core-shell": 74,
            "Pd cubes": 75,
            "NiCo2O4 MS": 76,
            "Multi-caged IrOx NPs": 77,
            "Fe3O4@Pt NPs": 78,
            "Fe3O4": 79,
            "Pt48Pd52-Fe3O4 dumbbell": 80,
            "Pt48Pd52 and Fe3O4 mixture": 81,
            "Pt48Pd52": 82,
            "TiO2?CA NPs": 83,
            "V2O5@pDA@MnO2": 84,
            "PtNFs/GNs": 85,
            "PdNPs/GNs": 86,
            "PtPdNDs/GNs": 87,
            "PtPdNAs/GNs": 88,
            "Pt@PdNFs/GNs": 89,
            "Naked-Fe3O4": 90,
            "Ala-Fe3O4": 91,
            "His-Fe3O4": 92,
            "Phenylalanine-Fe3O4": 93,
            " Glycine-Fe3O4": 94,
            "Leucine-Fe3O4": 95,
            "Isoleucine-Fe3O4": 96,
            "Valine -Fe3O4": 97,
            "Serine -Fe3O4": 98,
            "Threonine -Fe3O4": 99,
            "Proline-Fe3O4": 100,
            "Tyrosine-Fe3O4": 101,
            "Tryptophan -Fe3O4": 102,
            "Glutarnine-Fe3O4": 103,
            "Glutamic acidic-Fe3O4": 104,
            "Asparagine-Fe3O4": 105,
            "Aspartic acidic-Fe3O4": 106,
            "Lysine-Fe3O4": 107,
            "Arginine-Fe3O4": 108,
            "Cystine-Fe3O4": 109,
            "Methionine-Fe3O4": 110,
            "Pd Nanocrystals": 111,
            "F-CeO2": 112,
            "Pt nanoparticle": 113,
            "Fe3O4-Ncit": 114,
            "Fe3O4-NCMD  ": 115,
            "Fe3O4-Nhep": 116,
            "Fe3O4-Ngly": 117,
            "Fe3O4-NPLL ": 118,
            "Fe3O4-NPEI": 119,
            "Fe0.5Mn0.5Fe2O4": 120,
            "Fe3O4-ATP": 121,
            "Fe3O5-ATP": 122,
            "Fe3O4 NPs": 123,
            "Fe3O4 -AMP": 124,
            "PMCS": 125,
            "CoｊTBPP(bpy)": 126,
            "TiN NPS": 127,
            "PtNP": 128,
            "PtNP-A10": 129,
            "PtNP-T10": 130,
            "PtNP-C10": 131,
            "PtNP-G10": 132,
            "3D-g-C3N4/\nMIL-101(Fe)": 133,
            "3D-g-C3N4/\nMIL-102(Fe)": 134,
            "2D-g-C3N4/\nMIL-103(Fe)": 135,
            "2D-g-C3N4/\nMIL-104(Fe)": 136,
            "1D-g-C3N4/\nMIL-105(Fe)": 137,
            "1D-g-C3N4/\nMIL-106(Fe)": 138,
            "Mo-SAN": 139,
            "Fe/CN-800-A ": 140,
            "Fe2O3": 141,
            "(H2TCPP-污-Fe2O3)": 142,
            "HccFn(Co3O4)": 143,
            "HccFn(Fe3O4)": 144,
            "Fe3O4@Cu@Cu2O": 145,
            "Fe3O4 QDs": 146,
            "a-Fe2O3": 147,
            "Cu-GMP": 148,
            "Pt5": 149,
            "Pt20": 150,
            "BSA-Pt": 151,
            "RuO2": 152,
            "BSA-Au": 153,
            "solvothermal CeVO4": 154,
            "sonochemical CeVO4": 155,
            "hydrothermal CeVO4": 156,
            "Dex-NZM": 157,
            "BSA- Ag NCs -Hg": 158,
            "cp-Pt": 159,
            "cp-Au/Pt": 160,
            "gold@platinum nanorods": 161,
            "Au NPs": 162,
            "CoOxH-GO": 163,
            "CoOxH-GO + CN?": 164,
            "Fe3O4-N-GO": 165,
            "Fe3O4-Au-GO": 166,
            "PtNPs/rGO": 167,
            "GSF@AuNPs ": 168,
            "Free MNPs": 169,
            "GO_MNP 0": 170,
            "GO_MNP-30": 171,
            "Free Pt NPs": 172,
            "GO_Pt 0": 173,
            "GO_MNP 0每Pt 0": 174,
            "GO_MNP-30每Pt 0": 175,
            "PtNPs/GO": 176,
            "NiO": 177,
            "H2TCPP-NiO": 178,
            "MSN-AuNPs ": 179,
            "Co3O4": 180,
            "Ru NPs": 181,
            "Fe3O4@MnO2": 182,
            "GO-T10-PtNPs": 183,
            "GO-T20-PtNPs": 184,
            "GO-T30-PtNPs": 185,
            "GO-T40-PtNPs": 186,
            "Fe2NC ": 187,
            "Fe1NC ": 188,
            "Fe2NC": 189,
            "Fe1NC": 190,
            "Cu-NC": 191,
            "NiCo2O4@PVP": 192,
            "Cyt c": 193,
            "Cyt c@PCN-222 NP": 194,
            "Ru NCs/LDH": 195,
            "Ru1/LDH": 196,
            "5∩-end-DBA-Cu2+ -CDs": 197,
            "3∩-end-DBA-Cu2+ -CDs": 198,
            "5∩-end-DBA-(TGTA)--Cu2+ -CDs": 199,
            "5∩-end-DBA-(TGTA)2-Cu2+ -CDs": 200,
            "5∩-end-DBA-(TGTA)3-Cu2+ -CDs": 201,
            "5∩-end-TBA-Cu2+ -CDs": 202,
            "3∩-end-TBA-Cu2+ -CDs": 203,
            "5∩-end-TBA-(TGTA)-Cu2+ -CDs": 204,
            "5∩-end-TBA-(TGTA)2-Cu2+ -CDs": 205,
            "5∩-end-TBA-(TGTA)3-Cu2+ -CDs": 206,
            "Mn/PSAE": 207,
            "PEG-Pd SAzymes ": 208,
            "PEG-SHylated Cu-HCF": 209,
            "GSH treated PEG-SHylated Cu-HCF": 210,
            "Cu-NC-700": 211,
            "MIL-53(Fe)/G4-hemin": 212,
            "MIL-101(Fe)": 213,
            "MIL-101(CuFe)": 214,
            "MIL-101(CuFe)-CD147": 215,
            "cobalt-doped Ti3C2 MXene": 216,
            "ZnBNC": 217,
            "CDs@NC": 218,
            "Fe-N/C": 219,
            "Cu-N-C": 220,
            "Fe, N-CDs": 221,
            "MnCo2O4": 222,
            "R-MnCo2O4": 223,
            "Fe-Pt Alloys": 224,
            "H2TCPP-ZnS": 225,
            "CoSe2": 226,
            "CeO2 NRs": 227,
            "SO4/CeO2 NRs(SO4揭燴腔CeO2 NRs)": 228,
            "Fe SAEs": 229,
            "Cu2MoS4": 230,
            "PtFe@Fe3O4": 231,
            "PtFe": 232,
            "Pt@HCS NPs": 233,
            "HCS@Pt NPs": 234,
            "Co3O4@Co-Fe oxide DSNCs": 235,
            "Co-Fe oxide SSNCs": 236,
            "Co3O4 SSNCs": 237,
            "MOF-818": 238,
            "Fe-N-C": 239,
            "Pd/Pt NWs": 240,
            "FeP@C": 241,
            "PtNPs@MWCNTs": 242,
            "copper sulfide": 243,
            "Bare CuS": 244,
            "CuS-Asp0.05": 245,
            "h-CuS NCs": 246,
            "CuS-BSA-Cu3(PO4)2": 247,
            "50Co/CuS-MMT": 248,
            "CuS NPs": 249,
            "CuS-rGO": 250,
            "TiO2 nanotube arrays": 251,
            "CuS clews": 252,
            "CoS": 253,
            "BNNS@CuS": 254,
            "MoS2-GSSG": 255,
            "CuS-MMT": 256,
            "Ac-G9/Pt NP": 257,
            "Au@Pt0.25 NRs": 258,
            "Au@Pt0.25": 259,
            "Au@Pt0.17": 260,
            "Au@Pt0.10": 261,
            "Au@Pt": 262,
            "0.4Cu-CDs ": 263,
            "His@AuNCs": 264,
            "His@AuNCs/G": 265,
            "His@AuNCs/GO": 266,
            "His@AuNCs/RGO": 267,
            "ATP-Cu": 268,
            "Mn-Co NS": 269,
            "Co/Mn-MOF": 270,
            "Co3O4/CuO HNCs": 271,
            "bare CeO2": 272,
            "CeO2@PAA2K": 273,
            "CeO2@PAA5K": 274,
            "FeAC/FeSA-NC": 275,
            "Fe-N-C SAzymes ": 276,
            "apo-TF-MnOx NFs": 277,
            "carbon dots ": 278,
            "Au@MnO2-X nanozymes ": 279,
            "SrTiO3 nanosheets ": 280,
            "A-Pd@MoO3?x NH": 281,
            "rGO@FeS2": 282,
            "rGO@PDA@CeO2": 283,
            "rGO@PDA@CeO2/ATP ": 284,
            "rGO@PDA@CeO2/ATP/aptamer ": 285,
            "FeSx/MoS2@rGO": 286,
            "Au@HCNs": 287,
            "V2O5": 288,
            "MoO3": 289,
            "污-Fe2O3 NPs": 290,
            "污-Fe2O4 NPs": 291,
            "PVP-IrNPs": 292,
            "Au-Ft": 293,
            "Fe3(PO4)2﹞8H2O NFs": 294,
            "Pd-Pt NP": 295,
            "MoS2 QDs": 296,
            "MoS2 QDs/GQDs": 297,
            "BiOI": 298,
            "Au0.1/BiOI": 299,
            "Au1/BiOI": 300,
            "Au10/BiOCl": 301,
            "VS2": 302,
            "Fe3S4-MNPs": 303,
            "WS2 nanosheets": 304,
            "MoS2 NSs": 305,
            "CuZnFeS NCs": 306,
            "Cu(OH)2 SCs": 307,
            "Cu2(OH)3Cl-CeO2": 308,
            "Fe2(MoO4)3-F": 309,
            "汕-CD-Cu-NCs": 310,
            "BSA-Cu-NCs": 311,
            "ZnFe2O4 MNPs": 312,
            "FeS": 313,
            "FeSe": 314,
            "BiOBr": 315,
            "Fe0.5Co0.5 NPs": 316,
            "Fe NPs": 317,
            "Co NPs": 318,
            "VO2 (B)": 319,
            "GO每Fe3O4 ": 320,
            "Fe-MSN": 321,
            "Co3O4 ": 322,
            "CeO2 NPs ": 323,
            "Pt-Decorated BN ": 324,
            "WS2 + Ag NCs": 325,
            "WS2": 326,
            "Ag NCs": 327,
            "Pd@污Fe2O3": 328,
            "WC NRs": 329,
            "PtNPs@MnO2": 330,
            "MnO2 nanosheets": 331,
            "PtNPs": 332,
            "Ru@HA-MoS2": 333,
            "MnFe2O4": 334,
            "BSA-MnO2": 335,
            "Pt NCs": 336,
            "PSS-Au@Pt0.16 NRs": 337,
            "PSS-Au@Pd0.2Pt NRs": 338,
            "PSS-Au@PdPt NRs": 339,
            "Hg2+ Cit每AgNPs": 340,
            "CeO2@MPEG5KMPh": 341,
            "CeO2@MPEG2KMPEGa1K-MPh": 342,
            "CeO2@MPEG2KMPEGa2K-MPh": 343,
            "CeO2@MPEG2KMPh": 344,
            "IrNPs": 345,
            "Cerium Oxide": 346,
            "vanadium oxide": 347,
            "RuPt": 348,
            "Pt(Pt-Ft)": 349,
            "Au@0.17Pt": 350,
            "Au@0.25Pt": 351,
            "Pd@Pt core每frame nanodendrities": 352,
            "Pt hollow nanodendrites": 353,
            "CeO2?x": 354,
            "HBPG-AuNPs": 355,
            "CF@CuAl-LDH": 356,
            "CuSe": 357,
            "CuSeㄗCu2-xSeㄘ": 358,
            "CuSeㄗCu2-xSedcㄘ": 359,
            "CuSeㄗCu2-xSeshㄘ": 360,
            "Cu3Se2(GSH)": 361,
            "MoS2 Nanosheets": 362,
            "Cu-Ag/rGO": 363,
            "Ag/rGO": 364,
            "Cu2O/rGOㄗCu/rGOㄘ": 365,
            "Cu NPs": 366,
            "Au NPs/PVP-GNs": 367,
            "Au NPs/Cit-GN": 368,
            "AuNPs/GNs": 369,
            "Cit-AuNPs": 370,
            "Cu-Cys": 371,
            "NACu-Cys": 372,
            "Au-Ag AFT": 373,
            "Au-Ag NPs": 374,
            "Co-SAC": 375,
            "Co0.5Ni0.5Fe2O4-MMT": 376,
            "RhN4": 377,
            "VN4": 378,
            "FeN 4": 379,
            "CuN 4 ": 380,
            "Fe-Cu-N6": 381,
            "Cu-TCPP(Fe)": 382,
            "CsPbCl3NCs@PL": 383,
            "CsPbBr3NCs@PL": 384,
            "CsPbI3NCs@PL": 385,
            "Mn每CdTe(1)": 386,
            "Mn每CdTe(2)": 387,
            "Mn每CdTe(3)": 388,
            "FeOOH@Fe-Serine@Au": 389,
            "Co-Fe LDHs(2:1)": 390,
            "Co-Fe LDHs(1:1)": 391,
            "Co-Fe LDHs(1:2)": 392,
            "Co-Fe LDHs@Au": 393,
            "Co-Fe LDHs@Au+NIR": 394,
            "PS@Au@PB": 395,
            "Ce-Fe3O4 NPs": 396,
            "Fe3O4 ": 397,
            "Au/汐汕FeOOH每APC ": 398,
            "Fe3(PO4)2(OH)2": 399,
            "Fe?(PO?)?(OH)?": 400,
            "Fe3+-Doped Mesoporous Carbon": 401,
            "PBNPs": 402,
            "BiOCl": 403,
            "Na4.55Fe(PO4)2H0.45O": 404,
            "FeH3P2O8?H2O": 405,
            "Gly-Cu(OH)2 NPs": 406,
            "Cu(OH)2": 407,
            "MnO": 408,
            "MoO3_x0001_x nanodots ": 409,
            "1@SBA 5": 410,
            "2@SBA 5": 411,
            "2a@SBA 5": 412,
            "3@SBA 5": 413,
            "Ag-Au/AgCl nanohybrid": 414,
            "Fe-N-C SAzymes": 415,
            "AgVO3 nanobelts": 416,
            "Au/CeO2 CSNPs": 417,
            "AuNS@Ag每H每rGO": 418,
            "AuNP@Ag每H每rGO": 419,
            "H每rGO每Au34": 420,
            "CeO2 NC": 421,
            "5% Pr-CeO2 NC": 422,
            "10% Pr-CeO2 NC": 423,
            "15% Pr-CeO2 NC": 424,
            "20% Pr-CeO2 NC+NR": 425,
            "Zn-CuO": 426,
            "CuO": 427,
            "Cu-Pt Nanoalloys:": 428,
            "mixed-valence-state cobalt": 429,
            "MFNP1:1": 430,
            "MFNP2:1": 431,
            "MFNP3:1": 432,
            "MnOx NPs": 433,
            "Cu NCs": 434,
            "CuO NPs": 435,
            "Co3O4 NPs": 436,
            "Metal-free carbon nanozymes\nㄗQAU-Z1ㄘ": 437,
            "GNC-900 ": 438,
            "OV-Mn3O4 NFs": 439,
            "Mn3O4 NFs": 440,
            "CoNx-NC-650": 441,
            "BCNNTs\n": 442,
            "Cu/CeO2": 443,
            "CoFe2O4": 444,
            "SA-CoN3\n": 445,
            "SA-CoN4\n": 446,
            "SA Fe/B-g-C3N4": 447,
            "SA Fe/g-C3N4 ": 448,
            "MoS2": 449,
            "SA-Fe/NG ": 450,
            "MOF(Co/2Fe)": 451,
            "MVCM": 452,
            "ZIF-67": 453,
            "Bi每Au NPs": 454,
            "Fib-Bi每Au NPs": 455,
            "Pt0.1/Au NPs": 456,
            "MnO2 nanosheet": 457,
            "MnO2  sphere": 458,
            "MnO2 nanowire": 459,
            "MnO2 nanostick": 460,
            "bare AuNPs": 461,
            "ss-DNA每AuNPs": 462,
            "ds-DNA每AuNPs": 463,
            "T-MIP": 464,
            "T-MIPneg": 465,
            "A-MIP": 466,
            "A-MIPpos": 467,
            "Co3O4-F": 468,
            "V2O3-OMC": 469,
            "V2O5 Nanobelts": 470,
            "MnO2 ": 471,
            "Cu-TCPP MOF nanodots": 472,
            "CoNi NCs/NF@C": 473,
            "Cerium Oxide NSs": 474,
            "Mndpa@SiO2@IL每PEG": 475,
            "AdpaMn@SiO2@IL每PEG": 476,
            "VOx nanoflakes": 477,
            "CS-AgI": 478,
            "ZrO2": 479,
            "Co3O4 nanoplates": 480,
            "Co3O4 nanorods": 481,
            "Co3O4 nanocubes": 482,
            "PPy@CoO/NiO NTs": 483,
            "Au@PtAg0.33": 484,
            "Au@PtAg0.5": 485,
            "gold nanoparticles": 486,
            "FeSA": 487,
            "Pt clusters": 488,
            "FeSA-Pt": 489,
            "Fe55-N-C": 490,
            "H2O2-CeO2": 491,
            "BSA-H2O2-CeO2": 492,
            "PCNSs": 493,
            "N-PCNSs-5": 494,
            "N-PCNSs-3": 495,
            "FeN4C-SOx": 496,
            "SA-Pt/g-C3N4-K": 497,
            "g-C3N4-K": 498,
            "MoS2-CoFe2O4": 499,
            "NH 2 -MIL-88B (Fe)": 500,
            "NMCTP-TTA": 501,
            "AFt每CeO2 ": 502,
            "AFt每Pt": 503,
            "Pt NPs(PVP-Pt)": 504,
            "Ag-C12-3.0GEMA": 505,
            "Ag-C16-3.2GEMA": 506,
            "Ag-1.8C12-4.7GEMA": 507,
            "Pt-C12-3.0GEMA": 508,
            "Pt-C16-3.2GEMA": 509,
            "pt-1.8C12-4.7GEMA": 510,
            "CdCo2O4": 511,
            "Cu2O": 512,
            "Cu2O-CDs-Cu": 513,
            "Cu@Cu2O aerogels": 514,
            "NiFe2O4": 515,
            "ZnFe2O4": 516,
            "Fe3O4@indol-IL": 517,
            "IrNCs": 518,
            "Fe-Co-LDH": 519,
            "Pd cube@CeO2": 520,
            "BSA-Ag NCs": 521,
            "NL-MnCaO2": 522,
            "Co3O4-MMT NCs": 523,
            "FA-PMo4V8": 524,
            "Au/Co3O4-CeOx NCs": 525,
            "Pro-PtNPs": 526,
            "citrate-PtNPs": 527,
            "Ag@Fabric": 528,
            "Fe-AMP CPs": 529,
            "Co3O4/rGO": 530,
            "Co3O4  NPs": 531,
            "Ce-BPyDC": 532,
            "Pt nanoparticles": 533,
            "SA-PtNPs": 534,
            "HS-PtNPs": 535,
            "CuMnO2": 536,
            "Au-NPFe2O3NC": 537,
            "MoS2每Pt74Ag26": 538,
            "Ce-Bi/SiO2": 539,
            "Cit-IrNPs": 540,
            "Au-NH2": 541,
            "Au_Si_ACD": 542,
            "MnO2-Silk": 543,
            "Cu5.4O USNPs": 544,
            "SrFeO3-汛": 545,
            "La0.5Sr0.5MnO3-汛": 546,
            "La0.5Sr0.5FeO3-汛": 547,
            "LaMnO3-汛": 548,
            "CoO": 549,
            "LaCoO3-汛": 550,
            "Mn2O3": 551,
            "FHNPs": 552,
            "PDA/Fe3O4": 553,
            "RuNPs": 554,
            "Cu-CNNDs": 555,
            "BSA-Ce6&NO-RuO2": 556,
            "Co@SAHSs@IL-4@RCM": 557,
            "Co@SAHSs@IL-5@RCM": 558,
            "PtTS-SAzyme": 559,
            "TiO2 NPs": 560,
            "A-Ru": 561,
            "M-Ru": 562,
            "C-Ru": 563,
            "FeSNC SACs": 564,
            "NO2—MIL—101": 565,
            "NO2-MIL-101": 566,
            "NH2-MIL-101": 567}
    }

    req_json = request.get_json(force=True)

    # 初始化一个新的字典，用于存储处理后的数据
    processed_json = {}

    # 遍历 req_json 中的每个键值对
    for key, value in req_json.items():
        # 去除字符串两端的空白字符，并检查结果是否为空
        cleaned_value = value.strip()
        processed_json[key] = cleaned_value if cleaned_value != '' else None
        # processed_json 现在包含处理后的数据，其中空字符串和空格已替换为 None

    input_formula = processed_json.get('Chemical_formula')
    process_formula = find_similar_formula(input_formula, mapping)
    processed_json['Chemical_formula'] = process_formula

    results = predict_advanced(int(processed_json.get('Chemical_formula')),
                               int(processed_json.get('N')),
                               int(processed_json.get('P')),
                               int(processed_json.get('S')),
                               int(processed_json.get('Si')),
                               int(processed_json.get('Se')),
                               int(processed_json.get('B')),
                               int(processed_json.get('F')),
                               int(processed_json.get('Cl')),
                               int(processed_json.get('Br')),
                               int(processed_json.get('I')),
                               int(processed_json.get('shape')),
                               float(processed_json.get('size')),
                               int(processed_json.get('surface_modification')),
                               float(processed_json.get('buffer_pH')),
                               int(processed_json.get('temperature')),
                               int(processed_json.get('substrate_1')),
                               int(processed_json.get('substrate_2')),
                               float(processed_json.get('substrate2_concentration')))
    res = {
        "data": results
    }
    return jsonify(res)
